<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>修改密码</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../css/public.css" media="all">
    <link rel="stylesheet" href="../css/layuimini.css?v=2.0.4.2" media="all">
    <link rel="stylesheet" href="../css/themes/default.css" media="all">
    <link rel="stylesheet" href="../lib/font-awesome-4.7.0/css/font-awesome.min.css" media="all">
    <style>
        .layui-form-item .layui-input-company {
            width: auto;
            padding-right: 10px;
            line-height: 38px;
        }
    </style>
</head>

<body>
    <div class="layuimini-container">
        <div class="layuimini-main">

            <div class="layui-form layuimini-form">
                <div style="margin:15px 15px 15px 150px;color: #2F4056;">
                    <i class="fa fa-info-circle" style="margin-right: 5px;"></i>为了您的权益与安全，请不要将登录密码透露给他人，并且牢记您的新密码
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">当前密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="old_password" id="old_password" lay-verify="required"
                            lay-reqtext="当前密码不能为空" placeholder="当前密码" value="" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label required">新密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="new_password" id="new_password" lay-verify="required"
                            lay-reqtext="新密码不能为空" placeholder="新密码" value="" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label required">确认密码</label>
                    <div class="layui-input-block">
                        <input type="password" name="again_password" id="again_password" lay-verify="required"
                            lay-reqtext="确认密码不能为空" placeholder="确认密码" value="" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确定</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script src="../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <script>
        layui.use(['form', 'jquery', 'miniTab'], function () {
            var $ = layui.jquery,
                form = layui.form,
                layer = layui.layer,
                miniTab = layui.miniTab;

            //监听提交
            form.on('submit(saveBtn)', function (data) {
                var remember = 0; //是否记住密码
                var password = '';
                var username = '';
                var strCookie = document.cookie;
                if (strCookie != '') {
                    var arrCookie = strCookie.split("; ");
                    for (i = 0; i < arrCookie.length; i++) {
                        var arr = arrCookie[i].split("=");
                        if (arr[0] == 'username')
                            username = arr[1];
                        else if (arr[0] == 'remember')
                            remember = 1;
                        else if (arr[0] == 'password')
                            password = arr[1];
                    }
                }
                data1 = data.field;
                data1.username = username;
                var index = layer.alert(JSON.stringify(data.field), {
                    title: '最终的提交信息'
                }, function () {
                    if ($("#new_password").val() != $("#again_password").val())
                        layer.msg("两次密码输入不一致！");
                    else {
                        $.get('/pwd', data1, function (re) {
                            if (re == '1') {
                                data1.type = 'p';
                                $.get('/insert', data1, function (re2) {
                                    if (re2 == '3') {
                                        layer.close(index);
                                        miniTab.deleteCurrentByIframe();
                                    }
                                });
                            } else if (re == '2') {
                                layer.msg("原密码输入错误！");
                            }
                        })
                    }

                    // layer.close(index);
                    // miniTab.deleteCurrentByIframe();
                });
                return false;
                // }

            });

        });
    </script>
</body>

</html>